/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package commonlib.domain;

/**
 *
 * @author jorge.daniel.negrete
 */
import java.util.ArrayList;

public class Dictionary<T> extends TST<T>{
	  public Dictionary()
	  {
		  this.node=null;
	  }

	  public void addWord(String w)
	  {
		  this.add(w);
	  }
	  public boolean deleteWord(String w)
	  {
	      return this.delete(w);
	  }
	  public boolean findWord(String w)
	  {
		  return this.contains(w);
	  }
	  public void setAllDiccionary(ArrayList<String> DD)
	  {
		 this.addAll(DD);

	  }
	  public ArrayList<String> getAllDiccionary()
	  {
		  ArrayList<String> A=new ArrayList<String>();
		return getallDiccionario_recursivo(A,this.iterator(),"");
	  }

	  private ArrayList<String> getallDiccionario_recursivo(ArrayList<String> a,IteratorTST<T> i,String p)
	  {
		  Node<T> n;
		  if(i.hasNext()!=0)
		  {   n=i.next();

		     if(n.getMarked())
			   {
			    a.add(p+n.getLetter());
			   }
			  if(n.getMiddle()!=null)
			   {
				  a=this.getallDiccionario_recursivo(a,(IteratorTST<T>)i.clone(),p+n.getLetter());
			   }

			  while(i.hasNextBro())
			    {
				   n=i.nextBro();
				   if(n.getMarked())
				    {
					   a.add(p+n.getLetter());
				    }

				   if(n.getMiddle()!=null)
				    {
					   a=this.getallDiccionario_recursivo(a,(IteratorTST<T>)i.clone(),p+n.getLetter());
				    }
			    }
		  }
		 return a;

	  }
	}
